package com.acme.ionio.impl;

import com.acme.ionio.FileCopier;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Gregory Sobko
 */
public class FileCopierIO implements FileCopier {
    private static Logger logger = Logger.getLogger(FileCopierIO.class);

    @Override
    public void copy(File from, File to) throws IOException {
        try (FileInputStream fis = new FileInputStream(from); FileOutputStream fos = new FileOutputStream(to)){
            byte[] buffer = new byte[65536];
            int bytesRead = 0;
            while ((bytesRead = fis.read(buffer)) != -1){
                fos.write(buffer, 0, bytesRead);
            }
        }

    }
}
